home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / surfsrc3.zip / SHADOWS.INC < prev    next >
Text File  |  1991-09-25  |  3KB  |  105 lines

  1. procedure SHADOWS (var Shades: nodearray);
  2. { Flag the shades array with any nodes that are in a shadow. }
  3.  
  4. var Node:                      word;          { node # }
  5.     Surf:                      word;          { surface # }
  6.     Xfotran, Yfotran, Zfotran: real;          { transformed focal pt. }
  7.     { surface minimum & average (Ztran) }
  8.     XYmax:                     real;          { max coordinate }
  9.     Txeye, Tyeye, Tzeye:       real;          { temps for eye coords }
  10.     Tgxmin, Tgxmax, Tgymin, Tgymax: integer;  { temps for plot limits }
  11.     Tmagnify:                  real;          { temp for magnification }
  12.     Result:                    boolean;       { result of normalize setup }
  13. {$ifndef BIGMEM}
  14.     Surfmin, Surfmax: surfaces;
  15.       { surface minimum & maximum (Ztran) }
  16. {$endif}
  17.  
  18. begin
  19. {$ifdef BIGMEM}
  20. with ptra^ do with ptrb^ do with ptrc^ do
  21. with ptrd^ do with ptre^ do with ptrf^ do
  22. with ptrk^ do with ptrn^ do
  23. begin
  24. {$endif}
  25.  
  26.   menumsg ('Computing shadows...');
  27. { Preserve the old status before changing to shadowing values }
  28.   Txeye := Xeye;
  29.   Tyeye := Yeye;
  30.   Tzeye := Zeye;
  31.   Tgxmin := Gxmin;
  32.   Tgxmax := Gxmax;
  33.   Tgymin := Gymin;
  34.   Tgymax := Gymax;
  35.   Tmagnify := Magnify;
  36.  
  37. { New values to transform all nodes/surfaces as if they were being seen
  38.   by the primary light source. NOTE: This only works with a single light
  39.   source!
  40. }
  41.   Xeye := Xlite[1];
  42.   Yeye := Ylite[1];
  43.   Zeye := Zlite[1];
  44.   Gxmin := 0;         { shorten search time by using a coarser grid }
  45.   Gxmax := 100;
  46.   Gymin := 0;
  47.   Gymax := 100;
  48.   Magnify := 1.0;
  49.  
  50. { Transform from 3-D to 2-D coordinates }
  51.   setorigin;
  52.   for Node := 1 to Nnodes do
  53.     perspect (Xworld[Node], Yworld[Node], Zworld[Node],
  54.                  Xtran[Node],  Ytran[Node],  Ztran[Node]);
  55.  
  56. { Set plotting limits and normalize transformed coords to shadow-test coords }
  57.   perspect (Xfocal, Yfocal, Zfocal, Xfotran, Yfotran, Zfotran);
  58.   Result := setnormal (Xfotran, Yfotran, XYmax);
  59.  
  60. { Normalize all the nodes }
  61.   for Node := 1 to Nnodes do begin
  62.     normalize (Xtran[Node], Ytran[Node], Xfotran, Yfotran, XYmax);
  63.     { Initialize the Shades to zero }
  64.     Shades[Node] := 0.0;
  65.   end;
  66.   minmax (Surfmin, Surfmax, Nsurf);
  67.   shelsurf (Surfmin, Surfmax, Nsurf);
  68.  
  69.   for Node := 1 to Nnodes do begin
  70.     { Check every surface closer to the light source to see if it blocks
  71.     the light from this node. }
  72.     Surf := Nsurf;
  73.     while (Surf > 0) do begin
  74.       if (Surfmax[Surf] <= Ztran[Node]) then
  75.         { Gone past this node; flag that none of the remaining surfaces can
  76.         possibly be in front of it. }
  77.         Surf := 0
  78.       else if (Surfmin[Surf] > Ztran[Node]) then begin
  79.         { Only check surfaces that are completely in front of the node
  80.         (avoids surfaces that contain the node being considered in front
  81.         of the node) }
  82.         if (cheksurf (round(Xtran[Node]),round(Ytran[Node]),Surf)) then begin
  83.           Shades[Node] := -1.0;
  84.           { Flag to stop the loop }
  85.           Surf := 0;
  86.         end;
  87.       end; { if Surfmax }
  88.       Surf := Surf - 1;
  89.     end; { while }
  90.   end; { for Node }
  91.  
  92. { Done; now put things back the way we found them }
  93.   Xeye := Txeye;
  94.   Yeye := Tyeye;
  95.   Zeye := Tzeye;
  96.   Gxmin := Tgxmin;
  97.   Gxmax := Tgxmax;
  98.   Gymin := Tgymin;
  99.   Gymax := Tgymax;
  100.   Magnify := Tmagnify;
  101. {$ifdef BIGMEM}
  102. end; {with}
  103. {$endif}
  104. end; { procedure SHADOWS }
  105.